package homework.exp06;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Scanner;

public class H {
    static Scanner cin = null;

    static {
        try {
            cin = new Scanner(new FileInputStream(new File("src/homework/exp06/H.in")));
        } catch (IOException e) {
            cin = new Scanner(System.in);
        }
    }
    static class MatGraphClass {
        final int MaxV = 50;
        final int INF = 0X3F3F3F3F;
        int[][] edges;
        int n, e;
        int[] visited;
        String[] vexs;

        public MatGraphClass() {
            edges = new int[MaxV][MaxV];
            visited = new int[MaxV];
            vexs = new String[MaxV];
        }
    }

    public static void DFSTree(MatGraphClass g, int v) {
        System.out.print(v + " ");
        g.visited[v] = 1;
        for (int w = 0; w < g.n; w++) {
            if (g.edges[v][w] != 0) {
                if (g.visited[w] == 0)
                    DFSTree(g, w);
            }
        }
    }

    public static void main(String[] args) {

        while (cin.hasNext()) {
            int n;
            MatGraphClass g = new MatGraphClass();
            n = cin.nextInt();
            g.n = n;
            for (int i = 0; i < n; i++) {
                g.edges[i] = new int[n];
                for (int j = 0; j < n; j++)
                    g.edges[i][j] = cin.nextInt();
            }
            for (int i = 0; i < g.n; i++) {
                if (g.visited[i] == 0) {
                    DFSTree(g, i);
                    System.out.println();
                }
            }

        }
    }

}